<template>
  <div class="container with-nav-padding">
    <div class="myteam_banner" :style="{background: mainColor}">
      <p class="myteam_val">{{ teamNum }}</p>
      <p class="myteam_name">我的团队（个）</p>
    </div>
    <div class="team_tree">
      <ul>
        <li
          @click="item.isShow = !item.isShow"
          v-for="(item, index) in listArray"
        >
          <span class="member_img"><img :src="item.avatar" alt=""/></span>
          <span class="member_name">{{ item.nickname }}</span>
          <span class="member_type">{{ item.level }}</span>
          <span :class="{ childLevel_icon: true, 'icon-active': !item.isShow }"
            ><img src="@/assets/车主宝首页改-assets/返回.png" alt=""
          /></span>
          <div class="clear"></div>
          <ul
            :style="{ height: item.isShow ? 2 * item.teams.length + 'rem' : 0 }"
          >
            <li v-for="child in item.teams">
              <span class="child_member_img"
                ><img :src="child.avatar" alt=""
              /></span>
              <span class="child_member_name">{{ child.nickname }}</span>
              <span class="child_member_type">{{ child.level }}</span>
              <div class="clear"></div>
            </li>
          </ul>
        </li>
      </ul>
      <load-more @loadMore="loadMore"></load-more>
    </div>
  </div>
</template>

<script>
import { getTeamInfo } from "@/api/vip";
import loadMore from "@/components/load-more";
import { mapState } from "vuex";
export default {
  data() {
    return {
      isShow: true,
      listArray: [],
      page: 1,
      isAll: false,
      loading: false,
      teamNum: 0
    };
  },
  computed: {
    ...mapState({
      mainColor: state => state.app.mainColor,
      subColor: state => state.app.subColor
    })
  },
  methods: {
    getTeamInfo(page) {
      getTeamInfo({ page }).then(res => {
        if (res.status === 200) {
          this.teamNum = res.data.data.sum;
          let arr = res.data.data.center.map(item => {
            item.isShow = false;
            return item;
          });
          this.listArray.push(...arr);
          if (res.data.data.center.length === 0) {
            this.isAll = true;
            this.$dialog.toast({
              mes: "没有更多了",
              timeout: 1000
            });
          }
        }
        this.loading = false;
      });
    },
    loadMore() {
      if (this.loading || this.isAll || this.listArray.length === 0) return;
      this.loading = true;
      this.getTeamInfo(++this.page);
    }
  },
  created() {
    this.getTeamInfo(1);
  },
  components: {
    loadMore
  }
};
</script>

<style lang="less" scoped>
.container {
  padding-bottom: 2rem;
  .clear {
    clear: both;
  }

  .myteam_banner {
    background: #0678ff;
    width: 100%;
    padding-top: 1.5rem;
    height: 4.6rem;
    text-align: center;

    .myteam_val {
      font-weight: bold;
      font-size: 0.96rem;
      margin-bottom: 0.2rem;
      color: #ffffff;
    }

    .myteam_name {
      font-size: 0.56rem;
      color: #ffffff;
    }
  }

  .team_tree {
    ul {
      li {
        background: #ffffff;

        .member_img {
          width: 1.6rem;
          height: 1.6rem;
          margin: 0.4rem 0 0.4rem 0.48rem;
          overflow: hidden;
          float: left;
          border-radius: 50%;
          img {
            width: 100%;
            height: 100%;
          }
        }

        .member_name {
          font-size: 0.72rem;
          color: #444444;
          margin-top: 0.76rem;
          margin-left: 0.5rem;
          float: left;
        }

        .member_type {
          font-size: 0.52rem;
          color: #444444;
          padding: 0 0.24rem;
          height: 0.8rem;
          line-height: 0.8rem;
          text-align: center;
          color: #0078ff;
          margin-top: 0.9rem;
          margin-left: 0.5rem;
          border-radius: 0.4rem;
          float: left;
          border: 1px solid #0078ff;
        }

        .childLevel_icon {
          width: 0.52rem;
          margin: 0.9rem 0.38rem 0 0;
          transform: rotate(90deg);
          transition-duration: 0.2s;
          transform-origin: 20% 50%;
          float: right;
        }
        .icon-active {
          transform: rotate(0deg);
        }
        ul {
          overflow: hidden;
          transition-duration: 0.3s;
          li {
            background: #efefef;
            .child_member_img {
              width: 1.6rem;
              height: 1.6rem;
              overflow: hidden;
              margin: 0.2rem 0 0.2rem 1.1rem;
              float: left;
              background-color: #dfdfdf;
              border-radius: 50%;
              img {
                width: 100%;
                height: 100%;
              }
            }

            .child_member_name {
              font-size: 0.72rem;
              color: #444444;
              margin-top: 0.6rem;
              margin-left: 0.5rem;
              float: left;
            }

            .child_member_type {
              font-size: 0.52rem;
              color: #444444;
              padding: 0 0.24rem;
              height: 0.8rem;
              line-height: 0.8rem;
              text-align: center;
              color: #0078ff;
              margin-top: 0.6rem;
              margin-left: 0.5rem;
              border-radius: 0.4rem;
              border: 1px solid #0078ff;
              float: left;
            }
          }
        }
      }
    }
  }
}
</style>
